//
//  MQDiscoverSearchView.swift
//  MQWeibo
//
//  Created by 毛强 on 15/12/27.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

class MQDiscoverSearchView: UIView {

    
    
    @IBOutlet weak var textFieldrightConstraint: NSLayoutConstraint!
    @IBOutlet weak var textField: UITextField!
    @IBOutlet weak var cancelButton: UIButton!
    @IBAction func cancelButton(sender: UIButton) {
        
        self.textField.endEditing(false)
        self.textFieldrightConstraint.constant = 0
        UIView.animateWithDuration(0.25) { () -> Void in
            self.textField.layoutIfNeeded()
        }
    }
    
    @IBAction func textFiledDidBegin(sender: UITextField) {
        textFieldrightConstraint.constant = self.cancelButton.frame.width
        UIView.animateWithDuration(0.25) { () -> Void in
            self.textField.layoutIfNeeded()
        }
    }
    class func searchView() -> MQDiscoverSearchView {
        return NSBundle.mainBundle().loadNibNamed("MQDiscoverSearchView", owner: nil, options: nil).last! as! MQDiscoverSearchView
    }
    
    override func awakeFromNib() {
        let leftView = UIImageView()
        
        leftView.image = UIImage(named: "searchbar_textfield_search_icon")
        leftView.frame.size = CGSizeMake(frame.size.height, frame.size.height)
        leftView.contentMode = .Center
        textField.leftView = leftView
        textField.leftViewMode = .Always
        
//        textField.layer.cornerRadius = 8
//        textField.layer.borderWidth = 2
//        textField.layer.borderColor = UIColor.purpleColor().CGColor
    }
    
    //解档，但是未连线，所以不能使用该方法设置放大镜
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
